package com.qfedu.stussm.controller;

import com.qfedu.stussm.entity.Classes;
import com.qfedu.stussm.service.intf.ClassService;
import com.qfedu.stussm.vo.PageBeanVo;
import com.qfedu.stussm.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/api/class/")
public class ClassController {
    @Autowired
    private ClassService service;

    @PostMapping("addClass.do")
    public R addClass (Classes classes) {
        return service.addClass(classes);
    }
    @GetMapping("listClass.do")
    public PageBeanVo selectAll (String name, int page, int limit) {
        System.out.println(name);
        return service.selectAll(name, page, limit);
    }
    @PostMapping("delClass.do")
    public R delClass (int id) {
        System.out.println(id);
        return service.delClass(id);
    }
    @PostMapping("updateClass.do")
    public R updateClass (Classes classes) {
        return service.updateClass(classes);
    }
    @PostMapping("upload.do")
    public R upload(MultipartFile file) throws IOException {
        return service.uploadExcel(file);
    }
    //导出Excel
    @GetMapping("download.do")
    public void download(HttpServletResponse response) throws IOException {
        service.createExcel(response);
    }
    //统计
    @GetMapping("sel.do")
    public R sel () {
        return service.sel();
    }
}
